class EmptyStackException extends RuntimeException
{
	public EmptyStackException(String err)
	{
		super(err);
	}
	
}
class FullStackException extends RuntimeException
{
	public FullStackException(String err)
	{
		super(err);
	}
	
}
interface Stack<E>
{
	public boolean isEmpty();
	public E pop()throws EmptyStackException;
	public void push(E data);
	public boolean isFull();
	
	}

class ArrayStack <E> implements Stack<E> {
   protected E stackList[]; 
   int top=-1;
   public static final int MAX = 100; 
   
   public ArrayStack()    {
	   this(MAX);
   }
   public ArrayStack(int size)    {
      stackList = (E[]) new Object[size];
      top = -1; 
   }

public boolean isEmpty() 
{
	return(top==-1);
}

public E pop() throws EmptyStackException{
if(isEmpty())
	throw new EmptyStackException("Stack is Empty");
	
E temp=stackList[top];
	top--;
	return temp;
}


public void push(E data)  throws FullStackException{
	if(isFull()) throw new FullStackException("Full Stack Exception");
	stackList[++top]=data;
	} 
public boolean isFull()
{
	return(top==MAX-1);
	}
}// arraystack 

public class ArrayStackDemo {

public static void main(String[] args) {

	//ArrayStack<String> MStk=new ArrayStack<String>();
	//ArrayStack<Integer> MStk=new ArrayStack<Integer>();
	ArrayStack<Double> MStk=new ArrayStack<Double>();
	MStk.push(2.33); 
	MStk.push( 4.65 );
	MStk.push(23.12);
	System.out.println( MStk.pop() );
    System.out.println( MStk.pop() );
    System.out.println( MStk.pop() );
  
       }
} 
